#! /usr/bin/bash
# Contributor: Jevgeny Krasovsky <jkrasovsky@gmail.com>

_realname=qrencode
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.1.1
pkgrel=2
pkgdesc="C library for encoding data in a QR Code symbol (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
depends=("${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-SDL"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc")
url="https://fukuchi.org/works/qrencode/index.en.html"
license=('GPL')
source=(https://fukuchi.org/works/${_realname}/${_realname}-${pkgver}.tar.bz2)
sha256sums=('e455d9732f8041cf5b9c388e345a641fd15707860f928e94507b1961256a6923')

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-tests

  make
}

check () {
  make check -C build-${MSYSTEM}
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
  install -Dm0644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
